using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using Slaks.DocumentSerialization.Document;
using Slaks.VectorBasics;
using Slaks.VectorBasics.Containers;

namespace Slaks.Analysis.Forms
{
	/// <summary>
	/// Summary description for VectorComparisonView.
	/// </summary>
	public class VectorComparisonView : Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private Container components = null;

		private Document m_documentOne, m_documentTwo;
		private Vector m_vectorOne, m_vectorTwo;
		private TabControl m_tabControl;
		private TabPage m_informationTP;
		private RichTextBox m_informationRTB;
		private TabPage m_documentOneTP;
		private RichTextBox m_documentOneRTB;
		private TabPage m_documentTwoTP;
		private RichTextBox m_documentTwoRTB;
		private TabPage m_vectorOneTP;
		private RichTextBox m_vectorOneRTB;
		private TabPage m_vectorTwoTP;
		private RichTextBox m_vectorTwoRTB;
		private InformationADT m_informationAdt;
		private TabPage m_commonVectorTP;
		private RichTextBox m_commonVectorRTB;

		private Vector m_commonVector;

		public VectorComparisonView(Document documentOne, Document documentTwo, Vector vectorOne, Vector vectorTwo, Vector commonVector, InformationADT information)
		{
			InitializeComponent();
			m_documentOne = documentOne;
			m_documentTwo = documentTwo;
			m_vectorOne = vectorOne;
			m_vectorTwo = vectorTwo;
			m_commonVector = commonVector;
			m_informationAdt = information;
			ShowInformation();
			ShowDocument(m_documentOneRTB, m_documentOne);
			ShowVector(m_vectorOneRTB, m_documentOne, m_vectorOne);
			ShowDocument(m_documentTwoRTB, m_documentTwo);
			ShowVector(m_vectorTwoRTB, m_documentTwo, m_vectorTwo);
			//ShowVector(m_commonVectorRTB, m_documentOne, m_commonVector);
			this.Show();
		}

		private void ShowInformation()
		{
			StringBuilder builder = new StringBuilder();
			builder.Append("Representation : " + m_informationAdt.Representation + Environment.NewLine);
			builder.Append("DistanceValue : " + m_informationAdt.DistanceValue + Environment.NewLine);
			builder.Append("DistanceAlgorithm : " + m_informationAdt.DistanceAlgorithm + Environment.NewLine);
			builder.Append("Graph size : " + m_informationAdt.TypeSize + Environment.NewLine);
			builder.Append("File One: " + m_documentOne.FileName + Environment.NewLine);
			builder.Append("	Total terms in file one: " + m_documentOne.UniqueTermCount + Environment.NewLine);
			builder.Append("File Two: " + m_documentTwo.FileName + Environment.NewLine);
			builder.Append("	Total terms in file two: " + m_documentTwo.UniqueTermCount + Environment.NewLine);
			builder.Append("Mutual distance : " + m_informationAdt.MutualDistance + Environment.NewLine);
			m_informationRTB.Text += builder.ToString();
		}

		private void ShowDocument(Control control, Document document)
		{
			StringBuilder builder = new StringBuilder();

			foreach (Node node in document.Nodes)
			{
				builder.Append(node.Id + " " + node.Term + Environment.NewLine);

				foreach (Section section in node.Sections)
				{
					builder.Append("	Section : " + section.GetSectionTypeString() + Environment.NewLine);

					foreach (Sentence sentence in section.Sentences)
					{
						long nextId = sentence.NextId;
						if (nextId < 0) continue;
						string term = document.GetNodeById(nextId).Term;
						builder.Append("		Next-id : " + nextId + " , " + term + Environment.NewLine);
					}
				}
			}

			control.Text = builder.ToString();
		}

		private void ShowVector(Control control, Document document, Vector vector)
		{
			if (vector == null) return;
			StringBuilder builder = new StringBuilder();

			builder.Append("Vector name : " + vector.Name + Environment.NewLine + Environment.NewLine);
			VectorItemList vectorItemList = vector.GetVectorItemList();
			foreach (VectorItem vectorItem in vectorItemList)
			{
				builder.Append("Id : " + vectorItem.GetId() + ", " + document.GetNodeById(vectorItem.GetId()).Term + " , Frequency : " + vectorItem.Frequency + Environment.NewLine);
			}

			control.Text = builder.ToString();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.m_tabControl = new System.Windows.Forms.TabControl();
			this.m_informationTP = new System.Windows.Forms.TabPage();
			this.m_informationRTB = new System.Windows.Forms.RichTextBox();
			this.m_documentOneTP = new System.Windows.Forms.TabPage();
			this.m_documentOneRTB = new System.Windows.Forms.RichTextBox();
			this.m_documentTwoTP = new System.Windows.Forms.TabPage();
			this.m_documentTwoRTB = new System.Windows.Forms.RichTextBox();
			this.m_vectorOneTP = new System.Windows.Forms.TabPage();
			this.m_vectorOneRTB = new System.Windows.Forms.RichTextBox();
			this.m_vectorTwoTP = new System.Windows.Forms.TabPage();
			this.m_vectorTwoRTB = new System.Windows.Forms.RichTextBox();
			this.m_commonVectorTP = new System.Windows.Forms.TabPage();
			this.m_commonVectorRTB = new System.Windows.Forms.RichTextBox();
			this.m_tabControl.SuspendLayout();
			this.m_informationTP.SuspendLayout();
			this.m_documentOneTP.SuspendLayout();
			this.m_documentTwoTP.SuspendLayout();
			this.m_vectorOneTP.SuspendLayout();
			this.m_vectorTwoTP.SuspendLayout();
			this.m_commonVectorTP.SuspendLayout();
			this.SuspendLayout();
			// 
			// m_tabControl
			// 
			this.m_tabControl.Controls.Add(this.m_informationTP);
			this.m_tabControl.Controls.Add(this.m_documentOneTP);
			this.m_tabControl.Controls.Add(this.m_documentTwoTP);
			this.m_tabControl.Controls.Add(this.m_vectorOneTP);
			this.m_tabControl.Controls.Add(this.m_vectorTwoTP);
			this.m_tabControl.Controls.Add(this.m_commonVectorTP);
			this.m_tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_tabControl.Location = new System.Drawing.Point(0, 0);
			this.m_tabControl.Name = "m_tabControl";
			this.m_tabControl.SelectedIndex = 0;
			this.m_tabControl.Size = new System.Drawing.Size(792, 566);
			this.m_tabControl.TabIndex = 2;
			// 
			// m_informationTP
			// 
			this.m_informationTP.Controls.Add(this.m_informationRTB);
			this.m_informationTP.Location = new System.Drawing.Point(4, 22);
			this.m_informationTP.Name = "m_informationTP";
			this.m_informationTP.Size = new System.Drawing.Size(784, 540);
			this.m_informationTP.TabIndex = 2;
			this.m_informationTP.Text = "Information";
			// 
			// m_informationRTB
			// 
			this.m_informationRTB.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_informationRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
			this.m_informationRTB.Location = new System.Drawing.Point(0, 0);
			this.m_informationRTB.Name = "m_informationRTB";
			this.m_informationRTB.Size = new System.Drawing.Size(784, 540);
			this.m_informationRTB.TabIndex = 0;
			this.m_informationRTB.Text = "";
			// 
			// m_documentOneTP
			// 
			this.m_documentOneTP.Controls.Add(this.m_documentOneRTB);
			this.m_documentOneTP.Location = new System.Drawing.Point(4, 22);
			this.m_documentOneTP.Name = "m_documentOneTP";
			this.m_documentOneTP.Size = new System.Drawing.Size(784, 540);
			this.m_documentOneTP.TabIndex = 0;
			this.m_documentOneTP.Text = "Document One";
			this.m_documentOneTP.Visible = false;
			// 
			// m_documentOneRTB
			// 
			this.m_documentOneRTB.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_documentOneRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
			this.m_documentOneRTB.Location = new System.Drawing.Point(0, 0);
			this.m_documentOneRTB.Name = "m_documentOneRTB";
			this.m_documentOneRTB.ReadOnly = true;
			this.m_documentOneRTB.Size = new System.Drawing.Size(784, 540);
			this.m_documentOneRTB.TabIndex = 0;
			this.m_documentOneRTB.Text = "";
			// 
			// m_documentTwoTP
			// 
			this.m_documentTwoTP.Controls.Add(this.m_documentTwoRTB);
			this.m_documentTwoTP.Location = new System.Drawing.Point(4, 22);
			this.m_documentTwoTP.Name = "m_documentTwoTP";
			this.m_documentTwoTP.Size = new System.Drawing.Size(784, 540);
			this.m_documentTwoTP.TabIndex = 4;
			this.m_documentTwoTP.Text = "Document Two";
			this.m_documentTwoTP.Visible = false;
			// 
			// m_documentTwoRTB
			// 
			this.m_documentTwoRTB.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_documentTwoRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
			this.m_documentTwoRTB.Location = new System.Drawing.Point(0, 0);
			this.m_documentTwoRTB.Name = "m_documentTwoRTB";
			this.m_documentTwoRTB.Size = new System.Drawing.Size(784, 540);
			this.m_documentTwoRTB.TabIndex = 0;
			this.m_documentTwoRTB.Text = "";
			// 
			// m_vectorOneTP
			// 
			this.m_vectorOneTP.Controls.Add(this.m_vectorOneRTB);
			this.m_vectorOneTP.Location = new System.Drawing.Point(4, 22);
			this.m_vectorOneTP.Name = "m_vectorOneTP";
			this.m_vectorOneTP.Size = new System.Drawing.Size(784, 540);
			this.m_vectorOneTP.TabIndex = 1;
			this.m_vectorOneTP.Text = "Vector One";
			this.m_vectorOneTP.Visible = false;
			// 
			// m_vectorOneRTB
			// 
			this.m_vectorOneRTB.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_vectorOneRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
			this.m_vectorOneRTB.Location = new System.Drawing.Point(0, 0);
			this.m_vectorOneRTB.Name = "m_vectorOneRTB";
			this.m_vectorOneRTB.Size = new System.Drawing.Size(784, 540);
			this.m_vectorOneRTB.TabIndex = 0;
			this.m_vectorOneRTB.Text = "";
			// 
			// m_vectorTwoTP
			// 
			this.m_vectorTwoTP.Controls.Add(this.m_vectorTwoRTB);
			this.m_vectorTwoTP.Location = new System.Drawing.Point(4, 22);
			this.m_vectorTwoTP.Name = "m_vectorTwoTP";
			this.m_vectorTwoTP.Size = new System.Drawing.Size(784, 540);
			this.m_vectorTwoTP.TabIndex = 3;
			this.m_vectorTwoTP.Text = "Vector Two";
			this.m_vectorTwoTP.Visible = false;
			// 
			// m_vectorTwoRTB
			// 
			this.m_vectorTwoRTB.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_vectorTwoRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
			this.m_vectorTwoRTB.Location = new System.Drawing.Point(0, 0);
			this.m_vectorTwoRTB.Name = "m_vectorTwoRTB";
			this.m_vectorTwoRTB.Size = new System.Drawing.Size(784, 540);
			this.m_vectorTwoRTB.TabIndex = 0;
			this.m_vectorTwoRTB.Text = "";
			// 
			// m_commonVectorTP
			// 
			this.m_commonVectorTP.Controls.Add(this.m_commonVectorRTB);
			this.m_commonVectorTP.Location = new System.Drawing.Point(4, 22);
			this.m_commonVectorTP.Name = "m_commonVectorTP";
			this.m_commonVectorTP.Size = new System.Drawing.Size(784, 540);
			this.m_commonVectorTP.TabIndex = 5;
			this.m_commonVectorTP.Text = "Common vector";
			// 
			// m_commonVectorRTB
			// 
			this.m_commonVectorRTB.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_commonVectorRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
			this.m_commonVectorRTB.Location = new System.Drawing.Point(0, 0);
			this.m_commonVectorRTB.Name = "m_commonVectorRTB";
			this.m_commonVectorRTB.Size = new System.Drawing.Size(784, 540);
			this.m_commonVectorRTB.TabIndex = 0;
			this.m_commonVectorRTB.Text = "";
			// 
			// VectorComparisonView
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(792, 566);
			this.Controls.Add(this.m_tabControl);
			this.Name = "VectorComparisonView";
			this.Text = "VectorComparisonView";
			this.m_tabControl.ResumeLayout(false);
			this.m_informationTP.ResumeLayout(false);
			this.m_documentOneTP.ResumeLayout(false);
			this.m_documentTwoTP.ResumeLayout(false);
			this.m_vectorOneTP.ResumeLayout(false);
			this.m_vectorTwoTP.ResumeLayout(false);
			this.m_commonVectorTP.ResumeLayout(false);
			this.ResumeLayout(false);

		}

		#endregion
	}
}